# Import Module
from tkinter import *
# 注意需要导入messagebox
from tkinter import messagebox
# create root window
root = Tk()

# root window title and dimension
root.title("tkinter学习")
# Set geometry(widthxheight)
root.geometry('800x600')

def show_error():
    messagebox.showerror("错误", "这是一个错误消息")

def show_info():
    messagebox.showinfo("信息", "这是一个信息消息")

def show_warning():
    messagebox.showwarning("警告", "这是一个警告消息")

def show_ask():
    result =  messagebox.askquestion("询问", "请问你学会了吗?")
    if result == "yes":
        messagebox.showinfo("结果", "你学会了")
    else:
        messagebox.showinfo("结果", "你没学会")

btn = Button(root, text="错误", command=show_error)
btn.pack(pady=5)

btnInfo = Button(root, text="信息", command=show_info)
btnInfo.pack(pady=5)

btnWarning = Button(root, text="警告", command=show_warning)
btnWarning.pack(pady=5)

btnAsk = Button(root, text="询问", command=show_ask)
btnAsk.pack(pady=5)

# Execute Tkinter
root.mainloop()
